import { createApp } from 'vue'
import { createStore } from 'vuex'
import { getAPIList } from '../server'
import { RootObject, Child2, ChinaAdd, ChinaTotal, StatisGradeCityDetail } from "./type";

export const store = createStore({
    state: {
        count: <RootObject>{},
        children: <Child2[]>[],
        chinaAdd: <ChinaAdd>{},
        chinaTotal: <ChinaTotal>{},
        cityDetails: <StatisGradeCityDetail[]>[]
    },
    mutations: {
        getList(state, result) {
            state.count = result
            state.chinaAdd = result.diseaseh5Shelf.chinaAdd
            state.chinaTotal = result.diseaseh5Shelf.chinaTotal
            state.cityDetails = result.statisGradeCityDetail.slice(0,10)
            console.log(state.cityDetails);     
        }
    },
    actions: {
        async getList({ commit }) {
            const result = await getAPIList()
            commit('getList', result)
        }
    }
})

const app = createApp({ /* 根组件 */ })

// 将 store 实例作为插件安装
app.use(store)